package com.gec.anan.driver.service.impl;

import com.gec.anan.common.execption.AnanException;
import com.gec.anan.common.result.Result;
import com.gec.anan.common.result.ResultCodeEnum;
import com.gec.anan.driver.client.OcrFeignClient;
import com.gec.anan.driver.service.OcrService;
import com.gec.anan.model.vo.driver.DriverLicenseOcrVo;
import com.gec.anan.model.vo.driver.IdCardOcrVo;
import lombok.extern.slf4j.Slf4j;
import org.bouncycastle.jce.provider.AnnotatedException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class OcrServiceImpl implements OcrService {

    @Autowired
    private OcrFeignClient ocrFeignClient;

    /**
     * 身份证上传
     * @param file
     * @return
     */
    @Override
    public IdCardOcrVo idCardOcr(MultipartFile file) {
        return ocrFeignClient.idCardOcr(file).getData();
    }

    /**
     * 驾驶证上传
     * @param file
     * @return
     */
    @Override
    public DriverLicenseOcrVo driverLicenseOcr(MultipartFile file) {
        Result<DriverLicenseOcrVo> licenseOcrVoResult = ocrFeignClient.driverLicenseOcr(file);
        if(licenseOcrVoResult.getData() == null){
            throw new AnanException(licenseOcrVoResult.getCode(),licenseOcrVoResult.getMessage());
        }
        return licenseOcrVoResult.getData();
    }
}
